package nape.phys;
import cx.FastList;
import cx.Algorithm;
import nape.callbacks.Callbackable;
import nape.phys.PhysObj;















class Group extends Callbackable {
	static var nextId:Int;
	public var id:Int;
	
	public var objs:CxFastList(PhysObj);
	public var ignore:Bool;
	
	
	public var data:Dynamic;
	
	public function new() {
		id = nextId++;
		objs = new CxFastList(PhysObj)();
		
	}
	
	public inline function addObject(p:PhysObj) {
		if(!objs.has(p)) {
			objs.add(p);
			p.group_obj = this;
			return true;
		}else return false;
	}
	public inline function removeObject(p:PhysObj) {
		if(objs.remove(p)) {
			p.group_obj = null;
			CxIter(arb,p.p_objarb,{
				var grp = arb.group_arb;
				if(grp!=null && (grp.g1==this || grp.g2==this)) {
					grp.retire_arb(arb);
					arb.group_arb = null;
				}
			});
			return true;
		}else return false;
	}
}
